Python:higher-order function